using Microsoft.AspNetCore.Mvc;
using Zhaoxi.MSACommerce.CategoryService.UseCases.Command;
using Zhaoxi.MSACommerce.CategoryService.UseCases.Queries;
using Zhaoxi.MSACommerce.HttpApi.Common.Infrastructure;

namespace Zhaoxi.MSACommerce.CategoreService.HttpApi.Controllers;
[Route("api/category")]
[ApiController]
public class CategoryController:ApiControllerBase
{
    [HttpGet("children")]
    public async Task<IActionResult> GetCategoryAndChildren([FromQuery]GetCategoryAndChildrenQuery request)
    {
        var result = await Sender.Send(request);
        
        return ReturnResult(result);
    }
    [HttpGet("parents")]
    public async Task<IActionResult> GetCategoryAndParents([FromQuery]GetCategoryAndParentsQuery request)
    {
        var result = await Sender.Send(request);
        
        return ReturnResult(result);
    }

    [HttpGet(template: "parameters")]
    public async Task<IActionResult> GetParameters(long id)
    {
        var result = await Sender.Send(new GetParemetersByCategoryQuery(id));
        return ReturnResult(result);
    }
    
    
    [HttpPost]
    public async Task<IActionResult> Create(CreateCategoryCommand request)
    {
        var result = await Sender.Send(request);

        return ReturnResult(result);
    }
}